package com.marktotop.controller.system;

import com.marktotop.annotation.LogAnnotation;
import com.marktotop.dto.UserLoginDTO;
import com.marktotop.error.SystemException;
import com.marktotop.response.ResultBean;
import com.marktotop.service.ILoginLogService;
import com.marktotop.service.IRoleService;
import com.marktotop.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * LoginController
 *
 * @author WXLD
 * @Data 2021/7/12
 * @Since 1.0
 */
@RestController
@RequestMapping("/system")
@Api(tags = "系统模块-登录相关接口")
public class LoginController {

    @Autowired
    private IUserService userService;

    @Autowired
    private ILoginLogService loginLogService;

    /**
     * 用户登录
     *
     * @return
     */
    @ApiOperation(value = "用户登录", notes = "接收参数用户名和密码,登入成功后,返回JWTToken")
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResultBean login(@RequestBody UserLoginDTO userLoginDTO, HttpServletRequest request) throws SystemException {
        String token = userService.login(userLoginDTO.getUsername(),userLoginDTO.getPassword());
        loginLogService.add(request);
        return ResultBean.ok().data("token",token);
    }

    /**
     * 进入欢迎页
     *
     * @return
     */
    @ApiOperation(value = "控制面板", notes = "进入控制面板")
    @RequestMapping(value = "/welcome",method = RequestMethod.GET)
    public ResultBean showIndex(){
        return ResultBean.ok();
    }
}
